import { OperateBase } from '../../common/operate-base';
import { FontStylePlugin } from '../../../pugins/font-style.plugin';
export class FontBold extends OperateBase {
    protected container: HTMLElement;
    protected fontStylePlugin: FontStylePlugin;
    constructor() {
        super();
    }
    public afterDomInit(): void {
        this.zTableInstance.getHook().afterSelect.add((val) => {
            this.toggleDisabled(val !== null);
            this.disabled = val === null;
        });
        this.fontStylePlugin = this.zTableInstance.pluginManager.getPlugin(FontStylePlugin.pluginName);
        this.toggleDisabled(false);
    }
    protected toggleDisabled(isDisabled: boolean) {
        let ele: HTMLElement = this.container.querySelector('.iconfont');
        this.disabled = !isDisabled;
        if(!isDisabled) {
            ele.classList.add('z-table-icon-disabled');
        } else {
            ele.classList.remove('z-table-icon-disabled');
        }
    }
    public selectChange() {

    }
    public getDom() {
        let container = document.createElement('div');
        this.container = container;
        container.setAttribute('class', this.containerClassName);
        container.innerHTML=`<span class="z-tools-icon icon iconfont icon-font-weight" style="font-size: 16px;padding: 0px 3px;"></span>`;
        container.querySelector('.icon-font-weight').addEventListener('click', (e) => {
            if(this.disabled) return;
            let cells = this.fontStylePlugin.getSelectCells();
            let isNeedBold = false;
            for(let cell of cells) {
                if(cell.font.weight !== 900) {
                    isNeedBold = true;
                    break;
                }
            }
            if(isNeedBold) {
                this.fontStylePlugin.excute({weight: 900})
            } else {
                this.fontStylePlugin.excute({weight: 400})
            }
        });
        return container;
    }
}